package com.sopaths.utility.web;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class WebUtil {
	public static ServletRequest getRequest() {
		ServletRequestAttributes sra = (ServletRequestAttributes)(RequestContextHolder.currentRequestAttributes());
		ServletRequest request = sra.getRequest();
		return request;
	}

	public static HttpServletRequest getHttpServletRequest() {
		return (HttpServletRequest)getRequest();
	}

	public static HttpSession getHttpSession() {
		HttpServletRequest request = getHttpServletRequest();
		HttpSession session = request.getSession();
		return session;
	}

	public static void saveLastPageURI(String uri) {
		HttpSession session = getHttpSession();
		session.setAttribute("LAST_PAGE_URI", uri);
	}

	public static String getLastPageURI() {
		HttpSession session = getHttpSession();
		return session.getAttribute("LAST_PAGE_URI").toString();
	}
}
